try:
    fname = input('Please enter the file name: \n')
    if fname == '':
        fname = 'mbox.txt'
    fhand = open(fname, 'r')
except Exception as e:
    print('can\'t open the file "' + fname + '"')
    exit()

total = 0.0
count = 0
for line in fhand:
    if line.startswith('X-DSPAM-Confidence:'):
        pos = line.find(':')
        total += float(line[pos+1:].strip())
        count += 1


print(total / count)
# print(repr('Hello, \t, man'))

# s = '1,2,3'
# message, s = s.split(',', 1)  # 为什么可以这么写, 在第八章也许有解释...
# print(message, s)
